<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<base href="<?php echo base_url(); ?>" />
	<script type="text/javascript" src="assets/admintheme_blue/js/jquery-1.3.2.min.js"></script>
<style type='text/css'>
body
{
	font-family: Arial;
	font-size: 14px;
}
a {
    color: blue;
    text-decoration: none;
    font-size: 14px;
}
a:hover
{
	text-decoration: underline;
}
table {
	margin: 20px;
	border: 1px solid #ccc;
	width: 800px;
}
</style>

<script type="text/javascript">
var objData = {};
$(document).ready(function() {
	$('.relation_table').change(function() {
		var table = $(this).attr('alt');
		var v_table = $(this) . val();
		if(v_table != "") {
			var relation_id = $('#' + table + '_relation_id');
			var relation_display = $('#' + table + '_relation_display');
			var tmp = objData[v_table];
			relation_id.html('');
			relation_id.append('<option value="">-----------------</option>');

			relation_display.html('');
			relation_display.append('<option value="">-----------------</option>');

			for (var i=0;i<tmp.length;i++) {
				relation_id.append('<option value="' + tmp[i] + '">'+ tmp[i] +'</option>');
				relation_display.append('<option value="' + tmp[i] + '">'+ tmp[i] +'</option>');
			}
		}
	})
});

</script>
</head>
<body>
	<form method="POST" action="<?php echo site_url() . '/crud/generate' ;?>">
    <div>
		<?php foreach ($data as $table => $column) {
			?>
			<h1><?php echo $table; ?></h1>
			<script type="text/javascript">
				objData['<?php echo $table ; ?>'] = new Array(<?php echo '"' .join('","', $column) . '"'; ?>);
			</script>
			<table>
				<tr style="background: green;">
					<td>Column</td>
					<td>Display Name</td>
					<td>Show</td>
					<td>Add</td>
					<td>Edit</td>
					<td>Relation_Table</td>
					<td>Relation_id</td>
					<td>Relation_display</td>
					<td>Field Type</td>
				</tr>
				<?php foreach ($column as $col) { ?>
				<tr>
					<td><?php echo $col; ?></td>
					<td><input type="text" name="<?php echo $table . '_' . $col; ?>_display_name" value="<?php echo $col; ?>"/></td>
					<td><input type="checkbox" checked name="<?php echo $table . '_' . $col; ?>_show" value="1"/></td>
					<td><input type="checkbox" checked name="<?php echo $table . '_' . $col; ?>_add" value="1"/></td>
					<td><input type="checkbox" checked name="<?php echo $table . '_' . $col; ?>_edit" value="1"/></td>
					<td>
						<select alt="<?php echo $table . '_' . $col; ?>" class="relation_table" name="<?php echo $table . '_' .$col; ?>_relation">
							<option value="">-----------------</option>
							<?php foreach (array_keys($data) as $t) {
								if($table == $t) {
									continue;
								}
								echo '<option value="' . $t . '">'. $t .'</option>';
							}?>
						</select>
					</td>
					<td>
						<select id="<?php echo $table . '_' .$col; ?>_relation_id" name="<?php echo $table . '_' .$col; ?>_relation_id">
							<option value="">-----------------</option>
						</select>
					</td>
					<td>
						<select id="<?php echo $table . '_' .$col; ?>_relation_display" name="<?php echo $table . '_' .$col; ?>_relation_display">
							<option value="">-----------------</option>
						</select>
					</td>
					<td>
						<select name="<?php echo $table . '_' .$col; ?>_function">
							<option value="Text">Text</option>
							<option value="password">Password</option>
							<option value="time()">Hidden|time()</option>
							<option value="date('Y-m-d H:i:s')">Hidden|date('Y-m-d H:i:s')</option>
						</select>
					</td>
				</tr>
				<?php }?>
			</table>
		<?php } ?>
    </div>
    <input type="submit" value="Generate Code Admin"/>
	</form>
</body>
</html>
